package main

import (
	"dub/common"
	"dub/define"
	"dub/frame"
	"fmt"
)

type JavaServer struct {
	ln *frame.ListenerTcp //监听的服务器
}

func (j *JavaServer) lCallBack(mainId uint16, subId uint16, data []byte, ses common.ISession) bool {
	fmt.Println(string(data))
	ses.Send(uint16(1), uint16(1), ([]byte("收到消息")))
	return true
}

func (j *JavaServer) lnConnShutDown(ses common.ISession) bool {
	return j.lCallBack(define.CmdRegServer_Register, define.CmdSubRegServer_Register_Shut, nil, ses)
}

func (j *JavaServer) Start() {
	err := j.ln.Start()
	if err != nil {
		fmt.Println(err)
	}
}

func NewJavaServer(addr string) *JavaServer {
	js := &JavaServer{}
	js.ln = frame.NewListener(addr)
	js.ln.CallBack = js.lCallBack
	js.ln.OnShutdown = js.lnConnShutDown
	return js
}

func main() {
	js := NewJavaServer(":10167")
	js.Start()
}
